<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="送货" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/js/jquery.js"></script>
<script language="javascript">
	function doDeliver(id,favCost){
		var url="/business/DeliverBillNew.ihtm?business_bill_id="+id;
		ShowIframe("送货",url,1024,500,"doDeliverCallBack("+id+","+favCost+")");
	}
	function doDeliverCallBack(id,favCost){
		if(popRetVal!=null){
			var url=getProgramLocation()+"&current_page=${qr.pageIndex}";
			ShowConfirm('确认框','现在打印送货单？',340,80,"doDeliverCallBackPriExt('"+url+"',"+popRetVal+","+favCost+")");
		}else{
			document.getElementById("search_key").select();
		}
	}
	function doDeliverCallBackPriExt(url,id,favCost){
		if(popRetVal!=null){
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_BUSI_COST;')==-1}">
			//if(favCost==0){
				ShowConfirm('确认框','送货单打印金额？',340,80,"doDeliverCallBackCostExt('"+url+"',"+id+")");
			//}
			</c:if>
			<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_BUSI_COST;')!=-1}">
				url=url+"&print_id="+id+"&print_cost=0";
				window.location=url;
			</c:if>
		}else{
			window.location=url;
		}
	}
	function doDeliverCallBackCostExt(url,id){
		var printCost="0";
		if(popRetVal!=null){
			printCost="1";
		}
		var url=url+"&print_id="+id+"&print_cost="+printCost;
		window.location=url;
	}
	function getProgramLocation(){
		var searchKey=encodeURIComponent("${searchKey}");
		return "/business/BusinessBillListForDeliver.ihtm?search_key="+searchKey+"&type=${type}&order_by=${orderBy}&ts_id=${tsId}";
	}
	function doSearch(){
		var type=document.getElementById("type").value;
		var tsId=document.getElementById("ts_id").value;
		var orderBy=document.getElementById("order_by").value;
		var searchKey=encodeURIComponent(document.getElementById("search_key").value.trim());
		window.location="/business/BusinessBillListForDeliver.ihtm?search_key="+searchKey+"&type="+type+"&ts_id="+tsId+"&order_by="+orderBy+"&need_pop=Y";//点查询时才需要自动弹窗
	}
	function doGo(pageIndex){
		window.location=getProgramLocation()+"&current_page="+pageIndex;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		var favCost="0";
		if(ob_arr.length>=it.getAttribute("index")){
			str=ob_arr[it.getAttribute("index")-1].value;
			favCost = ob_arr[it.getAttribute("index")-1].getAttribute("fav_cost");
		}
		
		if(str==""){
			return;
		}
		doDeliver(str,favCost-0);
	}
	function doDownload(){
		window.location=getProgramLocation()+"&content_type=EXCEL";
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		//Window_Onload();
		document.getElementById("search_key").select();
		if(window.screen.availWidth>1024){
			var w=window.screen.availWidth*0.98;
			window.resizeTo(w,600);
			document.getElementById("mainDiv").style.width=(w-60)+"px";
			//居中
			var resizeWinTop=(window.screen.availHeight-600)/2;
			var resizeWinLeft=(window.screen.availWidth-w)/2;
			window.moveTo(resizeWinLeft,resizeWinTop);
		}
		
	}
	function checkSearchKey(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doPrint(id){
		showWin(900,600,"/business/BusinessBillPrint.ihtm?type=SIMPLE&id="+id);
	}
	function doSms(estIdStr,estName,billCode){
		var url="/sms/SmsSendForm.ihtm?est_id_str="+estIdStr;
		if(estName!=""){
			var content="尊敬的"+estName+"：您的订单"+billCode+"已完工，请准备收货，谢谢！";
			url=url+"&content="+encodeURIComponent(content);
		}
		showWin(900,500,url);
	}
	
	function doMutiSms(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(str!=""){
					str=str+";";
				}
				str = str+ob_arr[i].getAttribute("client_id");
			}
		}
		if(str!=""){
			doSms(str,"","");
		}else{
			ShowAlert('提示框','请选择要发短信的客户',200,100);
		}
	}
	function doMutiSend(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var str="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(str!=""){
					str=str+";";
				}
				str = str+ob_arr[i].value;
			}
		}
		if(str!=""){
			ShowConfirm('确认框','确定将选择的业务单直接设置为已送完货状态吗？',340,80,"doMutiSendCallBack('"+str+"')");
		}else{
			ShowAlert('提示框','请选择要送货的业务单',200,100);
		}
	}
	function doMutiSendCallBack(str){
		if(popRetVal!=null){
			document.getElementById("LoadProcess").style.top=getTopPos(document.getElementById("ts_id"))+50+"px";
			document.getElementById("LoadProcess").style.left=getleftPos(document.getElementById("ts_id"))+100+"px";
			$("#LoadProcess").show();
			$.post("/business/DeliverBillBatchNew.ihtm",{bus_id_str:str},function(data,status){
				doMutiSendCallBackExt(data,status);
			});
		}
	}
	function doMutiSendCallBackExt(data,status){
		if(status=="success"){
			var obj=$.parseJSON(data);
			if(obj.status=="NO_LOGIN"){
				window.location="/Login.ihtm";
			}else if(obj.status=="ERROR"){
				$("#LoadProcess").hide();
				ShowAlert('提示框',obj.errMsg,300,100);
			}else{
				$("#LoadProcess").hide();
				ShowConfirm('确认框','现在打印送货单？',340,80,"doMutiSendPrint('"+obj.idStr+"')");
			}
		}else{
			$("#LoadProcess").hide();
			ShowAlert('提示框','系统错误：'+status,300,100);
		}
	}
	function doMutiSendPrint(idStr){
		if(popRetVal!=null){
			<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_BUSI_COST;')==-1}">
			//if(favCost==0){
				ShowConfirm('确认框','送货单打印金额？',340,80,"doMutiSendPrintExt('"+idStr+"')");
			//}
			</c:if>
			<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_BUSI_COST;')!=-1}">
				var url=getProgramLocation()+"&current_page=${qr.pageIndex}";
				url=url+"&print_id="+idStr+"&print_cost=0&print_type=MULTI";
				window.location=url;
			</c:if>
		}else{
			refreshWin();
		}
	}
	function doMutiSendPrintExt(idStr){
		var printCost="0";
		if(popRetVal!=null){
			printCost="1";
		}
		var url=getProgramLocation()+"&current_page=${qr.pageIndex}";
		url=url+"&print_id="+idStr+"&print_cost="+printCost+"&print_type=MULTI";
		window.location=url;
	}
	
	function refreshWin(){
		window.location=getProgramLocation()+"&current_page=${qr.pageIndex}";//有print_id,print_cost,need_pop这些参数,所以这里不能直接refresh
	}
	function doPrintCallBack(){
		var printId="${printId}";
		var printCost="${printCost}";
		var printType="${printType}";
		if(printId!=null && printId!=""){
			if(printType!=null && printType=="MULTI"){
				showWin(900,600,"/business/DeliverBillPrintMulti.ihtm?id="+printId+"&print_cost="+printCost);
			}else{
				showWin(900,600,"/business/DeliverBillPrint.ihtm?id="+printId+"&print_cost="+printCost);
			}
		}else{
			<c:if test="${qr.totalCount==1 && needPop=='Y'}">
			doDeliver(${qr.list[0][0].id},${qr.list[0][0].favCost});
			</c:if>
		}
	}
	function showList(type){
		window.location="/business/BusinessBillListForDeliver.ihtm?type="+type;
	}
	function doLabel(id){
		var url="/business/BusinessBillInfoForLabel.ihtm?id="+id+"&wc_id=0";
		showWin(900,600,url);
	}
	function showRelBill(code){
		showWin(1024,600,"/business/BusinessRelBillList.ihtm?code="+encodeURIComponent(code));
	}
</script>
</head>
<c:set var="smsFlag" value="0" />
<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';SMS_SEND_SIMP;')!=-1}"><c:set var="smsFlag" value="1" /></c:if>
<body oncontextmenu="return false" onLoad="doInit();doPrintCallBack();" class="sheet">
<div class="sheet-main" style="width:980px" id="mainDiv">
  <div class="sheet-top">
    <div class="content">
      <h2>送货</h2>
      <p>根据业务单的交货日期、完工状态、送货状态进行分类查询，生成送货单。<span style="color:blue">蓝色</span>表示业务单已开过送货单</p>
    </div>
  </div>
  <div class="sheet-list">
    <div class="search-business">
      <div class="content">
        <table width="100%" id="searchTbl">
          <tbody>
            <tr>
              <td align="right">
				  <select name='ts_id' id="ts_id">
					<option value="0">==请选择账套==</option>
					<c:forEach var="item" items="${tsList}">
					<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
					</c:forEach>
		  		  </select>
				  <select name="type" id="type">
				  	<option value="">==全部==</option>
					<option value="UN_DELIVER" <c:if test="${type=='UN_DELIVER'}">selected</c:if>>全部未送货(不包括已部分送货的单)</option>
					<option value="UN_DELI_COMP" <c:if test="${type=='UN_DELI_COMP'}">selected</c:if>>完工未送货</option>
					<option value="UN_DELI_TIMEOUT" <c:if test="${type=='UN_DELI_TIMEOUT'}">selected</c:if>>超期未送货</option>
					<option value="UN_DELI_TIMEOUT_UN_COMP" <c:if test="${type=='UN_DELI_TIMEOUT_UN_COMP'}">selected</c:if>>未完工且超期未送货</option>
					<option value="UN_DELI_TIMEOUT_COMP" <c:if test="${type=='UN_DELI_TIMEOUT_COMP'}">selected</c:if>>已完工但超期未送货</option>
					<option value="PART_DELI" <c:if test="${type=='PART_DELI'}">selected</c:if>>部分送货</option>
				  </select>
				  <select name="order_by" id="order_by">
				  	<option value="">==排序==</option>
			  		<option value="EXAM_DATE" <c:if test="${orderBy=='EXAM_DATE'}">selected</c:if>>按审核日期</option>
			  		<option value="CREA_DATE" <c:if test="${orderBy=='CREA_DATE'}">selected</c:if>>按开单日期</option>
			  		<option value="ORDE_DATE" <c:if test="${orderBy=='ORDE_DATE'}">selected</c:if>>按订货日期</option>
			  		<option value="DELI_DATE" <c:if test="${orderBy=='DELI_DATE'}">selected</c:if>>按交货日期</option>
				  </select>
				  <input type="text" class="TextBox" id="search_key" name="search_key" onKeyUp="checkSearchKey();" style="width:80px" value="${searchKey}" title="以客户名称、客户拼音字头、摘要、业务单号、电话进行模糊查询">
				  <input type="button" class="buttom search-but" value=" 查 询" onClick="doSearch();" title="以客户名称、客户拼音字头、摘要、业务单号、电话进行模糊查询">
				  <input type="button" class="buttom search-add" value=" 送 货" onClick="doMutiSend();" title="直接将已选中的业务单设置为已送货，如果是同家客户，可以同时合并成一张送货单打印">
				  <input type="button" value=" 短 信" onClick="doMutiSms();" id="sSmsButton" name="sSmsButton" class="buttom search-sms" <c:if test="${smsFlag!='1'}">disabled="true"</c:if>>
			  </td>
            </tr>    
           </tbody>      
        </table>
      </div>
	  <%@include file="../inc/AlertMsg.jsp"%>
	  <div class="cue-info">
	  	选择：
	  	<a href="javascript:showList('');">全部</a>
	  	<a href="javascript:showList('UN_DELI_COMP');">完工未送货</a>
	  	<a href="javascript:showList('UN_DELI_TIMEOUT_COMP');">已完工且超期未送货</a>
	  	<a href="javascript:showList('UN_DELI_TIMEOUT');">超期未送货</a>
	  	<a href="javascript:showList('UN_DELI_TIMEOUT_UN_COMP');">未完工且超期未送货</a>
	  	<a href="javascript:showList('PART_DELI');">部分送货</a>
	  </div>
      <div class="table-list">
        <table width="100%">      
			<tr >
				<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
				<th  width="12%">单号</th>
				<th  width="8%">订货日期</th>
				<th  width="10%">订货单位</th>
				<th  width="12%">电话</th>
				<th  width="12%">摘要</th>
				<th  width="8%">交货日期</th>
				<th  width="10%">提货要求</th>
				<th  width="10%">安装要求</th>
				<th  width="6%">状态</th>
				<th  width="12%">操作</th>
			</tr>
			<c:forEach var="item" items="${qr.list}" varStatus="i">
				<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
				<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
				<c:set var="defaultFontColor" value="black" />
				<c:if test="${item[3]=='Y'}"><c:set var="defaultFontColor" value="blue" /></c:if>
				<tr class="${trClass}" index="${i.index+1}" style="color:${defaultFontColor};cursor:pointer;" defaultFontColor="${defaultFontColor}" ondblclick='javascript:DoubleClick(this)' onClick='javascript:ClickCheck(this,true)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
					<td><input type="checkbox" onClick="javascript:ClickCheck(this,true);" name='query_checkbox' value="${item[0].id}" fav_cost="${item[0].favCost}" client_id="${item[0].clientId}"></td>
					<td>${item[0].billCode}</td>
					<td><fmt:formatDate value="${item[0].orderDate}" pattern="yyyy-MM-dd"/></td>
					<td>${item[1]}<c:if test="${item[0].linkman!=null && item[0].linkman!=''}">(${item[0].linkman})</c:if></td>
					<td>${item[0].phone}</td>
					<td>${item[0].content}</td>
					<td>
						<c:if test="${item[0].deliverDate!=null}">
						<fmt:formatDate value="${item[0].deliverDate}" pattern="yyyy-MM-dd HH:mm"/>
						</c:if>
					</td>
					<td>${item[0].ladingRequire}</td>
					<td>${item[0].setupRequire}</td>
					<td>
						<c:if test="${item[2]=='N'}">未完工</c:if>
						<c:if test="${item[2]=='Y'}">已完工</c:if>
					</td>
					<td>
						<a href="javascript:doDeliver('${item[0].id}',${item[0].favCost});">送货</a>
						<a href="javascript:showRelBill('${item[0].billCode}');">查看</a>
						<c:if test="${smsFlag=='1'}"><a href="javascript:doSms('${item[0].clientId}','<c:out value="${item[1]}" />','<c:out value="${item[0].billCode}" />');"></c:if>发短信<c:if test="${smsFlag=='1'}"></a></c:if>
						<br>
						<a href="javascript:doLabel('${item[0].id}');">打印标签</a>
						<a href="javascript:doPrint('${item[0].id}');">打印制作单</a>
					</td>
				</tr>
			</c:forEach>
		</table>
		<%@include file="../inc/Pages.jsp"%>
      </div>     
    </div>
  </div>
</div>
<%@ include file="../inc/LoadingDiv.jsp"%>
</body>
</html>

